package io.gitee.mingbaobaba.security.oauth2.service;

import io.gitee.mingbaobaba.security.oauth2.domain.*;
import io.gitee.mingbaobaba.security.oauth2.domain.model.AuthorizeModel;
import io.gitee.mingbaobaba.security.oauth2.enums.GrantType;

/**
 * <p>授权服务</p>
 *
 * @author yingsheng.ye
 * @version 1.0.0
 * @since 2023/9/9 21:54
 */
public interface SecurityOauth2Service {

    /**
     * 授权码认证
     * 接收参数 client_id  redirect_uri  response_type  scope state
     *
     * @return 授权码
     */
    AuthorizeModel buildAuthorize();

    /**
     * 构建授权码返回地址
     *
     * @return 授权码地址
     */
    String buildAuthorizationCodeUri(String authorizationCode);

    /**
     * 构建应用信息
     *
     * @return true/false
     */
    SecurityOauth2Application buildSecurityOauth2Application();

    /**
     * 构建认证参数
     *
     * @param grantType 授权类型
     * @return SecurityAuthorizationModel
     */
    SecurityOauth2Client buildAuthorizationModel(GrantType grantType);

    /**
     * 根据授权码换取SecurityOauth2AccessToken信息
     *
     * @param authorizationCode 授权码
     * @return SecurityOauth2AccessToken
     */
    SecurityOauth2AccessToken getAccessTokenByAuthorizationCode(String authorizationCode);

    /**
     * 撤销授权
     *
     * @param authorizationCode 授权码
     */
    void revokeAuthorization(String authorizationCode);

    /**
     * 授权登录
     *
     * @param clientModel SecurityClientModel
     * @param grantType   授权类型
     * @return SecurityOauth2AccessToken
     */
    SecurityOauth2AccessToken grantAuthorizationLogin(SecurityOauth2Client clientModel, GrantType grantType);

    /**
     * 刷新token
     *
     * @return SecurityOauth2RefreshToken
     */
    SecurityOauth2RefreshToken refreshToken();

    /**
     * 获取用户信息
     *
     * @param accessToken 登录token
     * @return SecurityOauth2Details
     */
    SecurityOauth2Details getUserInfo(String accessToken);

}
